home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 4.5 KB | 131 lines | [TEXT/MPS ] |
- #
- # File: TimeLib.vu
- #
- # Contains: Tasks that make it easier to work with time in VU.
- #
- # Written by: Sean Flynn
- #
- # Copyright: © 1990-1992 by Apple Computer, Inc., all rights reserved.
- #
- # Change History (most recent first):
- #
- # <4> 6/17/92 DGG Changed format of printTime, added getTime
- # <3> 8/26/91 Rick Marked new Tasks
- # 6/11/91 Rick fixed task TimeElapsed
- # 1/17/91 Rick added task TimeElapsed
- # 1/25/91 naga modified header and edited formats
- #
- # To Do:
- #
-
- (************************************************************************************
- *Task WaitForTime( endHour := 0, endMinute := 0, endSecond := 0 )
- * WaitForTime task. Wait until a specified time of day.
- ************************************************************************************)
- task WaitForTime( endHour := 0, endMinute := 0, endSecond := 0 )
- begin
- while match [time h:?h2 s:?s2] and
- ( h2 / 100 <> endHour or
- h2 mod 100 < endMinute or
- s2 < endSecond ) do;
- end;
-
- (************************************************************************************
- * Task GetCurrentTime(returnDate := true)
- * This task returns the current time. The format is as follows:
- * <hour of day>:<minutes>:<seconds> <AM or PM>
- * It also takes one parameter that indicates whether the date should be printed.
- * If the actual parameter passed is a true value, the current date is also printed.
- * If no parameter is passed, the date is printed by default.
- * The format of the date is as follows:
- * <month>/<day>/<year>
- *
- ************************************************************************************)
- task GetCurrentTime(returnDate := true)
- begin
- timeString := "";
- match [time h:?hour s:?secs d:?day m:?month y:?year];
- hourOfDay := (hour / 100);
- if (hour < 1200)
- begin # in AM
- if (hourOfDay)
- timeString := numToStr(hourOfDay);
- else
- timeString := '12';
- meridian := ' AM';
- end;
- else
- begin # in PM
- if (hourOfDay = 12)
- timeString := timeString + numToStr(hourOfDay);
- else
- timeString := timeString + numToStr(hourOfDay - 12);
- meridian := ' PM';
- end;
- timeString := timeString + ':' + numToStr((hour mod 100) / 10) +
- numToStr(hour mod 10) + ':' + numToStr(secs) + meridian;
- if (returnDate)
- timeString := timeString + " " + numToStr(month) + "/" + numToStr(day) + "/" +
- numToStr((year mod 100) / 10) + numToStr(year mod 10);
- return timeString;
- end;
-
- (************************************************************************************
- *Task PrintCurrentTime(returnDate)
- * This task pretty prints the current time. The format is as follows:
- * <hour of day>:<minutes>:<seconds> <AM or PM>
- * It also takes one parameter that indicates whether the date should be printed.
- * If the actual parameter passed is a true value, the current date is also printed.
- * If no parameter is passed, the date is printed by default.
- * The format of the date is as follows:
- * <month>/<day>/<year>
- *
- ************************************************************************************)
- task PrintCurrentTime(printDate := true)
- begin
- println GetCurrentTime(printDate);
- end;
-
- (************************************************************************************
- * Task TimeElapsed( startTime, stopTime )
- * This task computes the difference between the start & stop time descriptors and
- * returns the result as a time desciptor. The dates are ignored.
- ************************************************************************************)
- task TimeElapsed( StartTime, stopTime )
- begin
-
- startHour := startTime.h / 100;
- startMinute := startTime.h mod 100;
- startSecond := startTime.s;
-
- stopHour := stopTime.h / 100;
- stopMinute := stopTime.h mod 100;
- stopSecond := stopTime.s;
-
- ##### Subtract seconds column
- if( stopSecond < startSecond ) ### must borrow from minutes column
- begin
- if( stopMinute = 0 ) ### must borrow from hours column
- begin
- stopHour := stopHour - 1; ### borrow 60 minutes from hours column
- stopMinute := stopMinute + 60;
- end;
- stopMinute := stopMinute - 1; ### borrow 60 seconds from minutes column
- stopSecond := stopSecond + 60;
- end;
- stopSecond := stopSecond - startSecond; ### finally subtract the seconds
-
- ##### Subtract minutes column
- if( stopMinute < startMinute ) ### must borrow from hours column
- begin
- stopHour := stopHour - 1; ### borrow 60 minutes from hours column
- stopMinute := stopMinute + 60;
- end;
- stopMinute := stopMinute - startMinute; ### finally subtract the minutes
-
- ##### Subtract Hours column
- stopHour := stopHour - startHour;
-
- return [ time y:0 m:0 d:0 h:(( stopHour * 100 ) + stopMinute) s:stopSecond ];
- end;
-